home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
399_01
/
mined1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-03
|
49KB
|
2,078 lines
/* ================================================================== *
* Editor mined *
* Part 1 *
* for documentation see mined.doc *
* ================================================================== */
#include "mined.h"
/* #define DEBUG */
/* ================================================================== *
* Definitions specific for mined1.c *
* ================================================================== */
#ifndef helpcommand
# ifdef unix
# define helpcommand "man mined"
# endif
# ifdef vms
# define helpcommand "help mined"
# endif
# ifdef msdos
# define helpcommand "more < %smined.hlp"
# endif
#endif
#ifndef printcommand
# ifdef unix
# ifdef sysV
# define printcommand "lp %s"
# else
# define printcommand "lpr %s"
# endif
# endif
# ifdef vms
# define printcommand "print %s"
# endif
# ifdef msdos
# define printcommand "copy %s prn: > nul:"
# endif
#endif
/* ================================================================== *
* Data section *
* ================================================================== */
LINE * header; /* Head of line list */
LINE * tail; /* Last line in line list */
LINE * cur_line; /* Current line in use */
LINE * top_line; /* First line of screen */
LINE * bot_line; /* Last line of screen */
char * cur_text; /* Current char on current line in use */
int last_y; /* Last y of screen. Usually SCREENMAX */
int x = 0, y = 0; /* x, y coordinates on screen */
short YMAX, XMAX;
char screen [screen_BUFL + 1]; /* I/O buffer for "writes" and "reads" */
int total_lines = 0; /* Number of lines in file */
long total_chars = -1L; /* Number of characters in file */
FLAG modified = FALSE; /* Set when file is modified */
FLAG viewonly = FALSE; /* Set when view only mode is selected */
FLAG overwriteOK = FALSE; /* Set if current file is OK for overwrite */
FLAG writable; /* Set if file cannot be written */
FLAG loading = TRUE; /* Loading a file? Init TRUE for error handling */
FLAG quit = FALSE; /* Set when quit character is typed */
FLAG intr_char = FALSE; /* Set when intr character is typed */
FLAG winchg = FALSE; /* Set when window size has changed */
FLAG isscreenmode = FALSE; /* Set when screen mode is on */
FLAG stat_visible; /* Set if status_line is visible */
FLAG fstat_always = FALSE; /* Permanent file status display wanted ? */
FLAG waitingforinput = FALSE; /* Set while waiting for the next command key */
FLAG rpipe = FALSE; /* Set if file should be read from stdin */
FLAG wpipe = FALSE; /* Set if file should be written to stdout */
FLAG multiexit = TRUE; /* Should exit command go to next file? */
FLAG proportional = FALSE; /* Enable support for proportional fonts? */
FLAG controlQS = FALSE; /* must respect ^Q/^S handshake ? */
FLAG insert_mode = TRUE; /* insert or overwrite */
uchar control_prefix = '\026'; /* ^V/^P character to prefix control chars */
FLAG Chinese = FALSE; /* set if two-byte characters are enabled */
FLAG page_scroll = FALSE; /* use scroll for page up/down */
FLAG page_stay = FALSE; /* stay at edge of screen after page up/down */
#ifdef pc
int display_delay = 9; /* delay between display lines */
#else
int display_delay = -1; /* Unix terminals are slow enough anyway */
#endif
#ifdef msdos
char RET_opt = 'r'; /* handle RET chars: ignore / newline */
#else
char RET_opt = ' '; /* handle RET chars: ignore / newline */
#endif
long chars_saved; /* Nr of chars in buffer */
int input_fd = STD_IN; /* File descriptors for terminal dialog */
int output_fd = STD_ERR;
int out_count = 0; /* Index in output buffer */
char file_name [maxLINE_LEN]; /* Name of file in use */
char text_buffer [MAX_CHARS]; /* for get_line, modifications, build_string */
int hop_flag = 0; /* Counter for the HOP function */
char TABchar = ' '; /* Char to be shown in place of tab chars */
char SHIFT_BEG = '\0'; /* Char indicating that line continues left */
char RET_MARK = '\0'; /* Char indicating end of line */
char RET_BLANK = '\0'; /* Char to fill the end of line with */
char RET_BLANK2 = '\0'; /* Char to fill last position of line with */
#ifdef vms
int fprot = 0; /* To be used for file creatings */
int bufprot = 0; /* To be used for paste buffer file */
#else
int fprot = 0644; /* To be used for file creatings */
int bufprot = 0600; /* To be used for paste buffer file */
#endif
int fnami; /* Parameter index of current file name */
int fnami_min, fnami_max, fnami_cnt;
/* char * (* fnamv) []; */
char * * fnamv; /* Copy of argv. Points to program params */
int left_margin = 0;
int right_margin = 71;
/*
* Yank variables.
*/
char * temp_dir;
char yank_file [maxLINE_LEN];
char yankie_file [maxLINE_LEN];
char panic_file [maxLINE_LEN];
char mined_dir [maxLINE_LEN]; /* startup directory to locate help file */
/* ================================================================== *
* Text buffer routines *
* ================================================================== */
int old_x = 0; /* previous x position */
/*
* Find_x () returns the x coordinate belonging to address.
* (Tabs are expanded).
*/
int
find_x (line, address)
LINE * line;
char * address;
{
register char * textp = line->text;
register int x_left = get_shift (line->shift_count) * - SHIFT_SIZE;
register int x_in_line = 0; /* must start from 0 to calculate correct
tab positions (since SHIFT_SIZE is not guaranteed
to be a multiple of 8) */
/* Alright, SHIFT_SIZE is now guaranteed to be a multiple of 8
due to lots of display problems related to that matter.
Leave this code anyway. */
while (textp != address && * textp != '\0') {
if (is_tab (* textp ++)) /* Expand tabs */
x_in_line = tab (x_in_line);
else
x_in_line ++;
}
return x_in_line + x_left;
}
/*
* Find_address () returns the pointer in the line with given offset.
* (Tabs are expanded).
* find_address is only called by move_it ()
get_shift (cnt) is ((cnt) & DUMMY_MASK) ; DUMMY_MASK is 0x7F
tab (cnt) is (((cnt) + 8) & ~07)
is_tab (c) is ((c) == '\t')
*/
char *
find_address (line, new_x, cur_x)
LINE * line;
int new_x;
int * cur_x;
{
register char * textp = line->text;
register int tx = get_shift (line->shift_count) * - SHIFT_SIZE;
while (tx < new_x && * textp != '\n') {
if (is_tab (* textp)) {
if (new_x == old_x /* (* cur_x) */ - 1 && tab (tx) > new_x)
break; /* Moving left over tab */
else
tx = tab (tx);
}
else tx ++;
textp ++;
}
* cur_x = tx;
return textp;
}
/*
* inmultichar (string, charpoi) determines if charpoi points to the second
* byte of a multi-byte character within string
*/
int
inmultichar (string, charpoi)
uchar * string;
uchar * charpoi;
{
while (string < charpoi) {
if (multichar (* string)) {
string ++;
if (* string != '\n' /* would be an error */) string ++;
} else
string ++;
}
return string > charpoi;
}
/*
* move_to: move to given coordinates on screen.
* move_y: move to given line on screen, staying in last explicit column.
* move_address: move to given line at given text position.
* The caller must check that scrolling is not needed.
* If new x-position is < 0 or > XBREAK, move_it () will check if
* the line can be shifted. If it can it sets (or resets) the shift_count
* field of the current line accordingly. By this mechanism, the
* pseudo-x-positions LINE_START / LINE_END (a very small / big value)
* perform the appropriate positioning actions.
* Move also sets cur_text to the right char.
* "If we're moving to the same x coordinate, try to move the the x-coordinate
* used on the other previous call." -- This worked erroneously and was
* replaced by an explicit old_x variable and move_y call.
* move_address is directly called by move_next/previous_word(), re_search(), RDwin()
*/
void
move_it (new_x, new_address, new_y)
register int new_x;
int new_y;
char * new_address;
{
register LINE * line = cur_line; /* For building new cur_line */
int shift = 0; /* How many shifts to make */
/* static int rel_x = 0; */ /* Remember relative x position */
/* This was used as a trick to stay virtually in the previous column
even when moving acro